﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;

namespace LI4.Data
{
    class Distrito
    {
        private Ligacao ligacao;

        public Distrito()
        {
            ligacao = new Ligacao();
        }

        public ArrayList getDistritos()
        {
            ArrayList array = new ArrayList();
            SqlDataReader reader;

            ligacao.Select("SELECT cod_distrito,nome FROM Distritos ORDER BY nome");
            reader = ligacao.mySqlDataReader;

            while (reader.Read())
                array.Add(new Business.Distrito(reader.GetInt32(0), reader.GetString(1)));

            reader.Close();
            return array;
        }

        public Business.Distrito getDistrito(int codigo)
        {
            SqlDataReader reader;

            ligacao.Select("SELECT nome FROM Distritos where cod_distrito='" + codigo + "'");
            reader = ligacao.mySqlDataReader;
            reader.Read();

            Business.Distrito distrito = new Business.Distrito(codigo, reader.GetString(0));

            reader.Close();

            return distrito;
        }

        public ArrayList getDistritosCod()
        {

            ArrayList array = new ArrayList();

            SqlDataReader reader;



            ligacao.Select("SELECT cod_distrito,nome FROM Distritos ORDER BY cod_distrito");

            reader = ligacao.mySqlDataReader;



            while (reader.Read())

                array.Add(new Business.Distrito(reader.GetInt32(0), reader.GetString(1)));



            reader.Close();

            return array;

        }

        public Business.Distrito getDistritoNome(string nomed)
        {
            SqlDataReader reader;

            ligacao.Select("SELECT * FROM Distritos where nome='" + nomed + "'");
            reader = ligacao.mySqlDataReader;
            reader.Read();
            int codigo = reader.GetInt32(0);

            Business.Distrito distrito = new Business.Distrito(codigo, nomed);

            reader.Close();

            return distrito;
        }

        public ArrayList getDistritosNome(string nomep)
        {
            ArrayList array = new ArrayList();
            SqlDataReader reader;
            Business.Distrito distrito;

            ligacao.Select("SELECT * FROM Distritos where nome ='" + nomep + "';");
            reader = ligacao.mySqlDataReader;
            while (reader.Read())
            {

                distrito = new Business.Distrito(reader.GetInt32(0), reader.GetString(1));
                array.Add(distrito);

            }

            reader.Close();
            return array;
        }
    }
}
